﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Web;
using System.IO;

namespace Comm
{
    public class PublicType
    {
        /// <summary>
        /// 获取语言列表
        /// </summary>
        /// <returns></returns>
        public static DataSet getLanguage()
        {
            DataSet ds = new DataSet();
            ds.ReadXml(HttpContext.Current.Server.MapPath("/xml/Language.xml"));

            return ds;
        }

        /// <summary>
        /// 获取根据ID语言名称
        /// </summary>
        /// <returns></returns>
        public static string getLanguageName(object obj)
        {
            if (obj == null)
            {
                return "";
            }
            DataSet ds = getLanguage();
            DataRow[] rows = ds.Tables[0].Select("id='" + obj.ToString() + "'");
            if (rows == null || rows.Length < 1)
            {
                return "";
            }

            return rows[0]["name"].ToString();
        }

        /// <summary>
        /// 根据NameKey获取语言名称 
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static string getLanguageNameKey(object obj)
        {
            if (obj == null)
            {
                return "";
            }
            DataSet ds = getLanguage();
            DataRow[] rows = ds.Tables[0].Select("namekey='" + obj.ToString() + "'");
            if (rows == null || rows.Length < 1)
            {
                return "";
            }

            return rows[0]["name"].ToString();
        }
    }
}
